package com.example.demo.service;

import com.example.demo.entity.Order;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MqServiceImpl implements MqService {

    @Autowired
    RocketMQTemplate rocketMQTemplate;

    @Override
    public void asyncSendOrderInfo(String topicName, Message<Order> message) {

        rocketMQTemplate.asyncSend(topicName, message, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
//              log.info("{}的订单消息发送成功,状态为{}",message.getPayload(),sendResult.getSendStatus());
            }

            @Override
            public void onException(Throwable throwable) {
              log.error("{}的订单消息发送成功,状态为{}",message.getPayload(),throwable.getMessage());
            }
        });

    }
}
